<?

abstract class system_task
{
	const TYPE_PROJECT_RELATED = 1;
	const TYPE_SYSTEM_RELATED = 2;

	protected $type = 1;
	protected $output;
	public $silent_mode = false;

	public function  __construct( $output = null )
	{
		$this->output = $output;

		if ( ( $this->type == self::TYPE_SYSTEM_RELATED ) && defined('PROJECT_PATH') )
		{
			throw new Exception('This task should not be run inside existing project');
		}
		else if ( ( $this->type == self::TYPE_PROJECT_RELATED ) && !defined('PROJECT_PATH') )
		{
			throw new Exception('This task should bu run inside existing project');
		}
	}

	abstract public function execute( array $params = array() );

	public function out( $message = '' )
	{
		if ( $this->silent_mode ) return;

		$this->output ? $this->output->out( $message ) : null;
	}

	public function error( $message )
	{
		if ( $this->silent_mode ) return;

		echo "\033[40;31m";
		$this->output ? $this->output->out( 'ERROR: ' . $message ) : null;
		echo "\033[00m";
	}
}